package com.czk.rdd.operator.transform

import org.apache.spark.{SparkConf, SparkContext}

/**
 * @Author:ChenZhangKun
 * @Date: 2021/12/9 11:22
 */
object Spark06_RDD_Operator_Transform {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("RDD")
    val sc = new SparkContext(sparkConf)

    val rdd = sc.makeRDD(List(1, 2, 3, 4))

    val mapRDD=rdd.mapPartitionsWithIndex(
      (index,iter)=>{
        iter.map(
          // 拿到数据对应的分区
          num=>{
            (index,num)
          }
        )
      }
    )
    mapRDD.collect().foreach(println)
  }
}
